package com.cdtu.labpreview.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.cdtu.labpreview.common.Result;
import com.cdtu.labpreview.common.UserHolder;
import com.cdtu.labpreview.dto.UserDTO;
import com.cdtu.labpreview.entity.InstrumentIntroduction;
import com.cdtu.labpreview.entity.Talk;
import com.cdtu.labpreview.entity.Think;
import com.cdtu.labpreview.entity.ThinkingAndTips;
import com.cdtu.labpreview.mapper.TalkMapper;
import com.cdtu.labpreview.mapper.ThinkMapper;
import com.cdtu.labpreview.service.IThinkingAndTipsService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 思考题及提示模块
 */
@RestController
@RequestMapping("/thinkAndTopics")
@Api(tags = "思考题及提示模块")
public class ThinkingQuestionsAndTipsController {

    @Autowired
    private IThinkingAndTipsService thinkingAndTipsService;

    @Autowired
    private ThinkMapper thinkMapper;
    @Autowired
    private TalkMapper talkMapper;

    /**
     * 查看思考题及提示（老师、学生）
     * @return
     */
    @GetMapping
    public Result getThinkingQuestionsAndTips(){
        UserDTO userDTO = UserHolder.getUser();
        int no = userDTO.getUserNo();
        int type = userDTO.getType();
        return thinkingAndTipsService.getThinkingAndTips(no,type);
    }

    /**
     * 添加思考题
     * @param think
     * @return
     */
    @PostMapping("/think")
    public Result addThinkingQuestions(@RequestBody Think think){
        return thinkingAndTipsService.addThinking(think);
    }

    /**
     * 添加思考题及提示（老师）
     * @param thinkingAndTips
     * @return
     */
    @PostMapping
    public Result addThinkingQuestionsAndTips(@RequestBody ThinkingAndTips thinkingAndTips){
        return thinkingAndTipsService.addThinkingAndTips(thinkingAndTips);
    }

    /**
     * 修改思考题及提示（老师）
     * @param thinkingAndTips
     * @return
     */
    @PutMapping
    public Result updateThinkingQuestionsAndTips(@RequestBody ThinkingAndTips thinkingAndTips){
        return thinkingAndTipsService.updateThinkingAndTips(thinkingAndTips);
    }

    /**
     * 删除思考题及提示（老师）
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteThinkingQuestionsAndTips(@PathVariable("id") long id){
        return thinkingAndTipsService.deleteThinkingAndTips(id);
    }

    /**
     * 查看思考题及提示（老师、学生）
     * @return
     */
    @GetMapping("/allThink")
    public Result getAllThinking(){
        List<Think> thinks = thinkMapper.selectList(new LambdaQueryWrapper<>());
        return Result.ok(thinks);
    }

    /**
     * 添加思考题
     * @param talk
     * @return
     */
    @PostMapping("/talk")
    public Result addTalk(@RequestBody Talk talk){
        talk.setSno(UserHolder.getUser().getUserNo());
        talkMapper.insert(talk);
        return Result.ok();
    }
}
